home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2 Examples.sit / Raven 1.2 Examples / Quill / Source / ViewDecorations.cpp < prev    next >
Text File  |  1997-05-11  |  9KB  |  345 lines

  1. /*
  2.  *  File:       ViewDecorations.h
  3.  *  Summary:       Adorners and behaviors used in the view editor.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1996 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *  Change History (most recent first):    
  10.  *
  11.  *         <->     8/26/96    JDJ        Created
  12.  */
  13.  
  14. #include "ViewDecorations.h"
  15.  
  16. #include <LowMem.h>
  17.  
  18. #include <ZQDShapes.h>
  19. #include <ZQuickDrawUtils.h>
  20. #include <ZView.h>
  21.  
  22. #include "ViewCommands.h"
  23. #include "ViewTrackers.h"
  24.  
  25.  
  26. // ===================================================================================
  27. //    class COutlineAdorner
  28. // ===================================================================================
  29.  
  30. //---------------------------------------------------------------
  31. //
  32. // COutlineAdorner::~COutlineAdorner
  33. //
  34. //---------------------------------------------------------------
  35. COutlineAdorner::~COutlineAdorner()
  36. {
  37. }
  38.  
  39.  
  40. //---------------------------------------------------------------
  41. //
  42. // COutlineAdorner::COutlineAdorner
  43. //
  44. //---------------------------------------------------------------
  45. COutlineAdorner::COutlineAdorner() : TAdorner("COutlineAdorner", kNonPersistant)
  46. {
  47. }
  48.  
  49.  
  50. //---------------------------------------------------------------
  51. //
  52. // COutlineAdorner::GetExtent
  53. //
  54. //---------------------------------------------------------------
  55. TRect COutlineAdorner::GetExtent() const
  56. {
  57.     TRect extent = this->GetOwner()->GetExtent();
  58.     extent.Inset(-1, -1);
  59.     
  60.     return extent;
  61. }
  62.  
  63.  
  64. //---------------------------------------------------------------
  65. //
  66. // COutlineAdorner::OnDraw
  67. //
  68. //---------------------------------------------------------------
  69. void COutlineAdorner::OnDraw(TCanvas& canvas, const TRect& extent)
  70. {
  71. #if 1
  72.     TRegion oldClip = canvas.GetClip();
  73.     
  74.     canvas.SetClip(extent);
  75.     
  76.     TRectShape::Frame(canvas, extent, GetGray());
  77.  
  78.     canvas.SetClip(oldClip);
  79.  
  80. #else
  81.     TRectShape::Frame(canvas, extent, GetGray());
  82.  
  83.     TRegion clip = canvas.GetClip();
  84.     
  85.     TRect outer = extent;
  86.     TRect inner = extent;
  87.     inner.Inset(1, 1);
  88.     
  89.     clip -= TRegion(outer) - TRegion(inner);
  90.  
  91.     canvas.SetClip(clip);                            // don't let the pane draw over our handles
  92. #endif
  93. }
  94.  
  95. #pragma mark -
  96.  
  97. // ===================================================================================
  98. //    class CHandleAdorner
  99. // ===================================================================================
  100.  
  101. //---------------------------------------------------------------
  102. //
  103. // CHandleAdorner::~CHandleAdorner
  104. //
  105. //---------------------------------------------------------------
  106. CHandleAdorner::~CHandleAdorner()
  107. {
  108. }
  109.  
  110.  
  111. //---------------------------------------------------------------
  112. //
  113. // CHandleAdorner::CHandleAdorner
  114. //
  115. //---------------------------------------------------------------
  116. CHandleAdorner::CHandleAdorner() : TAdorner("CHandleAdorner", kNonPersistant)
  117. {
  118. }
  119.  
  120.  
  121. //---------------------------------------------------------------
  122. //
  123. // CHandleAdorner::OnDraw
  124. //
  125. //---------------------------------------------------------------
  126. void CHandleAdorner::OnDraw(TCanvas& canvas, const TRect& extent)
  127. {
  128.     TRGBColor color;
  129.     LMGetHiliteRGB(&color);
  130.     
  131.     TRegion clip = canvas.GetClip();
  132.     
  133.     TRect handle = extent;
  134.     handle.right  = handle.left + kHandleSize;
  135.     handle.bottom = handle.top + kHandleSize;    
  136.     clip -= handle;
  137.     TRectShape::Fill(canvas, handle, color);
  138.  
  139.     handle = extent;
  140.     handle.left   = handle.right - kHandleSize;
  141.     handle.bottom = handle.top + kHandleSize;    
  142.     clip -= handle;
  143.     TRectShape::Fill(canvas, handle, color);
  144.  
  145.     handle = extent;
  146.     handle.right = handle.left + kHandleSize;
  147.     handle.top   = handle.bottom - kHandleSize;    
  148.     clip -= handle;
  149.     TRectShape::Fill(canvas, handle, color);
  150.  
  151.     handle = extent;
  152.     handle.left = handle.right - kHandleSize;
  153.     handle.top  = handle.bottom - kHandleSize;    
  154.     clip -= handle;
  155.     TRectShape::Fill(canvas, handle, color);
  156.     
  157.     canvas.SetClip(clip);                            // don't let the pane draw over our handles
  158. }
  159.  
  160. #pragma mark -
  161.  
  162. // ===================================================================================
  163. //    class CNameAdorner
  164. // ===================================================================================
  165.  
  166. //---------------------------------------------------------------
  167. //
  168. // CNameAdorner::~CNameAdorner
  169. //
  170. //---------------------------------------------------------------
  171. CNameAdorner::~CNameAdorner()
  172. {
  173. }
  174.  
  175.  
  176. //---------------------------------------------------------------
  177. //
  178. // CNameAdorner::CNameAdorner
  179. //
  180. //---------------------------------------------------------------
  181. CNameAdorner::CNameAdorner(const string& name) : TAdorner(name, kNonPersistant), mTraits(200)
  182. {
  183.     mBackColor = TRGBColor(64000, 45824, 39936);    // ・・・ハload from a resource?
  184. }
  185.  
  186.  
  187. //---------------------------------------------------------------
  188. //
  189. // CNameAdorner::GetExtent
  190. //
  191. //---------------------------------------------------------------
  192. TRect CNameAdorner::GetExtent() const
  193. {
  194.     string text = this->GetText();
  195.     
  196.     return this->GetTextBox(text);
  197. }
  198.  
  199.  
  200. //---------------------------------------------------------------
  201. //
  202. // CNameAdorner::GetTextBox
  203. //
  204. //---------------------------------------------------------------
  205. TRect CNameAdorner::GetTextBox(const string& text) const
  206. {
  207.     TSize size = mTraits.GetStringSize(text);
  208.     
  209.     TRect box = Inherited::GetExtent();
  210.     box.bottom = box.top;
  211.     box.top    = box.bottom - size.height;
  212.     
  213.     STextTrait traits = mTraits.GetTraits();
  214.     
  215.     if (traits.justification == teFlushLeft)    
  216.         box.right = box.left + size.width;
  217.     else if (traits.justification == teFlushRight)
  218.         box.left = box.right - size.width;
  219.  
  220.     // If the box is outside the superView's extent move it into
  221.     // the pane.        
  222.     if (TPane* owner = dynamic_cast<TPane*>(this->GetOwner())) {
  223.         TView* superView = owner->GetSuperView();
  224.         if (superView != nil && !superView->GetExtent().Contains(box + owner->GetLocation()))
  225.             box += TPoint(0, size.height);
  226.     } 
  227.         
  228.     return box;
  229. }
  230.  
  231.  
  232. //---------------------------------------------------------------
  233. //
  234. // CNameAdorner::OnDraw
  235. //
  236. //---------------------------------------------------------------
  237. void CNameAdorner::OnDraw(TCanvas& canvas, const TRect& extent)
  238. {
  239.     #pragma unused(extent)
  240.     
  241.     TRegion oldClip = canvas.GetClip();
  242.  
  243.     string text = this->GetText();
  244.     TRect box = this->GetTextBox(text);
  245.     
  246.     canvas.SetClip(box);                
  247.     
  248.     TRectShape::Fill(canvas, box, mBackColor);
  249.     TTextShape::Draw(canvas, text, box, mTraits);
  250.  
  251.     oldClip -= box;
  252.     canvas.SetClip(oldClip);                
  253. }
  254.  
  255. #pragma mark -
  256.  
  257. // ===================================================================================
  258. //    class CPaneNameAdorner
  259. // ===================================================================================
  260.  
  261. //---------------------------------------------------------------
  262. //
  263. // CPaneNameAdorner::~CPaneNameAdorner
  264. //
  265. //---------------------------------------------------------------
  266. CPaneNameAdorner::~CPaneNameAdorner()
  267. {
  268. }
  269.  
  270.  
  271. //---------------------------------------------------------------
  272. //
  273. // CPaneNameAdorner::CPaneNameAdorner
  274. //
  275. //---------------------------------------------------------------
  276. CPaneNameAdorner::CPaneNameAdorner() : CNameAdorner("CPaneNameAdorner")
  277.     STextTrait traits = mTraits.GetTraits();
  278.     traits.justification = teFlushLeft;
  279.     mTraits = traits;
  280. }
  281.  
  282.  
  283. //---------------------------------------------------------------
  284. //
  285. // CPaneNameAdorner::GetText
  286. //
  287. //---------------------------------------------------------------
  288. string CPaneNameAdorner::GetText() const
  289. {
  290.     string text;
  291.     
  292.     if (TPane* pane = dynamic_cast<TPane*>(this->GetOwner()))
  293.         text = pane->GetName();
  294.         
  295.     return text;
  296. }
  297.  
  298. #pragma mark -
  299.  
  300. // ===================================================================================
  301. //    class CClassNameAdorner
  302. // ===================================================================================
  303.  
  304. //---------------------------------------------------------------
  305. //
  306. // CClassNameAdorner::~CClassNameAdorner
  307. //
  308. //---------------------------------------------------------------
  309. CClassNameAdorner::~CClassNameAdorner()
  310. {
  311. }
  312.  
  313.  
  314. //---------------------------------------------------------------
  315. //
  316. // CClassNameAdorner::CClassNameAdorner
  317. //
  318. //---------------------------------------------------------------
  319. CClassNameAdorner::CClassNameAdorner() : CNameAdorner("CClassNameAdorner")
  320.     STextTrait traits = mTraits.GetTraits();
  321.     traits.justification = teFlushRight;
  322.     mTraits = traits;
  323. }
  324.  
  325.  
  326. //---------------------------------------------------------------
  327. //
  328. // CClassNameAdorner::GetText
  329. //
  330. //---------------------------------------------------------------
  331. string CClassNameAdorner::GetText() const
  332. {
  333.     string text;
  334.  
  335.     if (MReanimatable* zombie = dynamic_cast<MReanimatable*>(this->GetOwner()))
  336.         text = zombie->GetClassName();
  337.     else
  338.         text = typeid(*this->GetOwner()).name();
  339.         
  340.     return text;
  341. }
  342.  
  343.